import {game} from "cc";

export class ServerTimeHelper {
    serverTimeMs: number = 0

    setServerTime(serverNowMS: number | undefined) {
        this.serverTimeMs = (serverNowMS ? serverNowMS : 0) - game.totalTime;
    }

    loadServerTime(): number {
        if (this.serverTimeMs == 0) return new Date().getTime();
        return Math.round(this.serverTimeMs + game.totalTime);
    }
}

export const serverTimeHelper = new ServerTimeHelper();